import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:realmega_ota/realmega/ota_manager.dart';

import 'ota_manager_ex.dart';

class UpdateWidget extends StatelessWidget{
  const UpdateWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      height: double.infinity,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          StreamBuilder<int>(
            stream: OtaManagerEx.instance.progress,
            initialData: 0,
            builder: (c, snapshot) => Stack(
              alignment: AlignmentDirectional.center,
              children: [
                Container(
                  width:160,
                  height: 160,
                  child: CircularProgressIndicator(
                    value: snapshot.data!/100,
                    backgroundColor: Colors.black12,
                    valueColor: const AlwaysStoppedAnimation<Color>(Colors.blueAccent),
                    strokeWidth: 16,
                  ),
                ),
                Text('${snapshot.data}%', style: const TextStyle(fontSize: 20),)
              ],
            ),
          ),
          Container(height: 20,),
          Text('芯片型号：${OtaManagerEx.instance.softRom.substring(0, 2)}00', style: const TextStyle(fontSize: 20)),
          Container(height: 10,),
          Text('ROM版本号：V${OtaManagerEx.instance.softRom.substring(2)}', style: const TextStyle(fontSize: 20)),
          Container(height: 10,),
          Text('当前软件版本号：${OtaManagerEx.instance.chipVersion}', style: const TextStyle(fontSize: 20)),
          Container(height: 10,),
          Text('升级软件版本号：${OtaManagerEx.instance.softVersion}', style: const TextStyle(fontSize: 20)),
          Container(height: 10,),
          Text('升级软件大小：${OtaManagerEx.instance.softSize}KB', style: const TextStyle(fontSize: 20)),
        ],
      ),
    );
  }

}